package Lambda;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        //有括号、有类型、无花括号、无返回
        MathOperation addition = (int a, int b) -> a + b;
        //有括号、无类型、无花括号、无返回
        MathOperation subtraction = (a, b) -> a - b;
        //有括号、有类型、有花括号、有返回
        MathOperation multiplication = (int a, int b) -> {
            return a * b;
        };
        //有括号、有类型、无花括号、无返回
        MathOperation division = (int a, int b) -> a / b;

        System.out.println("10+5="+main.operate(10,5,addition));
        System.out.println("10-5="+main.operate(10,5,subtraction));
        System.out.println("10*5="+main.operate(10,5,multiplication));
        System.out.println("10/5="+main.operate(10,5,division));

        //匿名内部类的简单实现
        GreetingService greetingService = message -> System.out.println("Hello," + message);
        GreetingService greetingService2 = (message) -> System.out.println("Hello," + message);

        greetingService.sayMessage("Bright");
        greetingService.sayMessage("Bright Liou");

    }

    interface MathOperation {
        int operation(int a, int b);
    }

    interface GreetingService {
        void sayMessage(String message);
    }

    private int operate(int a, int b, MathOperation mathOperation){
        return mathOperation.operation(a, b);
    }
}
